package week02;

import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapred.JobConf;
import org.apache.hadoop.mapred.Mapper;
import org.apache.hadoop.mapred.OutputCollector;
import org.apache.hadoop.mapred.Reporter;

import java.io.IOException;

public class Week02Mapper implements Mapper<Text, Text, Text, Week02OutputWritable> {


    @Override
    public void map(Text key1, Text value1, OutputCollector<Text, Week02OutputWritable> outputCollector, Reporter reporter) throws IOException {
        // 时间戳  电话号码  基站的物理地址  访问网址的IP  网站域名  数据包  接包数  上行/传流量  下行/载流量  响应码

        String[] fieldArray = value1.toString().split(" ");
        String mobile = fieldArray[1];
        String up = fieldArray[7];
        String down = fieldArray[8];


        Week02Output week02Output = new Week02Output();
        week02Output.setMobile(mobile);
        week02Output.setUpSize(Integer.valueOf(up));
        week02Output.setDownSize(Integer.valueOf(down));
        week02Output.setTotalSize(week02Output.getUpSize() + week02Output.getDownSize());
        Week02OutputWritable output = new Week02OutputWritable(week02Output);
        outputCollector.collect(new Text(mobile), output);

    }

    @Override
    public void close() throws IOException {

    }

    @Override
    public void configure(JobConf jobConf) {

    }
}
